import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
		shopping_cart:[],                                 //购物车
		receiving_address: '选择收货地址',                    //收货地址
		receiving_address_arr:[],                           //地址列表
		inputval:'',                                         //搜索地址val
		companyId: '',                                       //收货地址的id
		remarks_val:'',                                      //备注
		coupon_index:-1,                                     //优惠卷列表下标
		coupon_id:'',				                         //优惠卷id
		coupon_concessions:0,		                         //优惠卷价格
		coupon_ids:'',				                         //优惠卷ids 
		htp: 'https://www.iotry.net',                        //地址
		id:'',                                               //公用id
		openid:''		                                     //小程序openid
	},
    mutations: {
		//oppenid
		openid(state,stap) {
			state.openid = stap.oppenids
			state.id = stap.untids
		},
		//优惠券
		coupons(state,stap) {
			state.coupon_index = stap.coupon_index
			state.coupon_id = stap.coupon_id
			state.coupon_concessions = stap.coupon_concessions
			state.coupon_ids = stap.coupon_ids
		},
		//备注
		remarks(state,stap){
			state.remarks_val = stap
		},
		//获取地址列表
		receiving_address_list(state,stap){
			state.receiving_address_arr = stap
		},
		//获取input的val
		Inputvlue(state,stap){
			state.inputval = stap
		},
		//修改默认地址
		modify_shipping_address(state,stap) {
			state.receiving_address = stap.address
			state.companyId = stap.address_id
		},
	},
    actions: {},
	getters:{
		deliveryAddress(state) {
			if(state.inputval != ''){
				return state.receiving_address_arr.filter(item =>item.companyName.includes(state.inputval) )
			}
			return state.receiving_address_arr
			
		}
	}
})
export default store